let evts = {};

let domEvent = {
    on(dom, type, fn) {
        try {
            dom.addEventListener(type, fn);
        } catch (e) {
            throw new Error('Not Element');
        }
        if(!evts[type]) {
            evts[type] = [];
        }
        evts[type].push({
            dom: dom,
            fn
        });
    },
    off(type) {
        if(evts[type]) {
            evts[type].forEach(d => {
                d.dom.removeEventListener('type', d.fn);
            });
            delete evts[type];
        }
    },
    emit(type) {
        if(evts[type]) {
            evts[type].forEach(d => {
                d.fn();
            })
        }
    }
};
export default domEvent;